/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * main.c
 * Copyright (C) 陈跃辉 2011 <timercrack@gmail.com>
 *
 * HolyShield is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * HolyShield is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include <gtk/gtk.h>

/* store the widgets which may need to be accessed in a typedef struct */
typedef struct _Data Data;
struct _Data {
        GtkWidget *image_firewall_status;   /* status image */
        GtkWidget *label_firewall_status; /* status label */
        GtkWidget *window; /* Main window for HolyShield */
};

gboolean is_shutdown;

G_MODULE_EXPORT void toolbtn_run_clicked_cb(GtkWidget *widget, Data* data)
{
        //gtk-media-stop
        if (is_shutdown==TRUE) {
                gtk_label_set_markup (GTK_LABEL (data->label_firewall_status), g_strconcat ("<span size=\"small\">", "开启", "</span>", NULL));
                gtk_image_set_from_file(GTK_IMAGE(data->image_firewall_status),"icons/run.png");
                gtk_tool_button_set_stock_id ((GtkToolButton *)widget,"gtk-quit");
                is_shutdown = FALSE;
                //gtk-media-play
        } else {
                gtk_label_set_markup (GTK_LABEL (data->label_firewall_status), g_strconcat ("<span size=\"small\">", "关闭", "</span>", NULL));
                gtk_image_set_from_file(GTK_IMAGE(data->image_firewall_status),"icons/stop.png");
                gtk_tool_button_set_stock_id ((GtkToolButton *)widget,"gtk-media-play");
                is_shutdown = TRUE;
        }
}
int main(int argc, char *argv[])
{
        //这些語句声明了一些组件变量，由于GTK是面向对象的，
        //所以都可以声明为GtkWidget，这也是习惯作法
        Data HolyShield;
        GtkBuilder *builder;
        //GtkWidget *menubtn_exit;
        //GtkWidget *label;

        //每一个gtk程序都会用到这一句，用来初始化
        gtk_init(&argc, &argv);

        /*这个builder就是用来读取我们用Glade设计的界面的一个东西*/
        builder = gtk_builder_new();

        /*用下面这个gtk函数把gui.glade的内容给builder*/
        gtk_builder_add_from_file(builder, "gui.glade", NULL);

        /*通过名字从gui.glade中读取我们需要使用的组件*/
        HolyShield.window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
        HolyShield.image_firewall_status = GTK_WIDGET(gtk_builder_get_object(builder, "image_firewall_status"));
        HolyShield.label_firewall_status = GTK_WIDGET(gtk_builder_get_object(builder, "label_firewall_status"));
        is_shutdown = FALSE;

        /*这是glib里的一个函数，用来把一个组件与一个函数关联起来，下面
        这句就是把button和我们上面的那个on_button_clicked给关联了*/
        /*        g_signal_connect( G_OBJECT(menubtn_exit), "activate",*/
        /*                          G_CALLBACK(on_menubtn_exit), NULL);*/

        /*这条語句就是自动把所有的信号处理函数都关联好*/
        gtk_builder_connect_signals(builder, &HolyShield);

        /*因为我们已经不需要builder了，就释放builder的空间*/
        g_object_unref(G_OBJECT(builder));

        /*将window内所有的组件都显示出来，这们我们才能看见*/
        gtk_widget_show_all(HolyShield.window);

        /*这也是每一个gtk程序都要有的*/
        gtk_main();

        return 0;
}
